home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / dph_array.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.1 KB  |  73 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  dph_array.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_DPHARRAY_H
  16. #define LEDA_DPHARRAY_H
  17.  
  18. //------------------------------------------------------------------------------
  19. // dph_array  
  20. //------------------------------------------------------------------------------ 
  21. #include <LEDA/basic.h> 
  22. #include <LEDA/impl/slist.h> 
  23. #include <LEDA/impl/dp_hash.h> 
  24.  
  25.  
  26. template<class itype, class etype>
  27.  
  28. class _CLASSTYPE dph_array : public dp_hash {
  29.  
  30. void clear_key(GenPtr& x)   const { Clear(ACCESS(itype,x)); }
  31. void clear_inf(GenPtr& x)   const { Clear(ACCESS(etype,x)); }
  32. void copy_key(GenPtr& x)    const { x=Copy(ACCESS(itype,x));  }
  33. void copy_inf(GenPtr& x)    const { x=Copy(ACCESS(etype,x));  }
  34.  
  35. int  int_type() const { return 1; }
  36.  
  37. etype init;
  38. SLIST def_list;
  39.  
  40. public:
  41.  
  42. etype& operator[](itype y) { stp i=lookup(Convert(y));
  43.                              if (i==nil) { i=insert(Convert(y),Convert(init));
  44.                                            def_list.append(Convert(y));  }
  45.                              return ACCESS(etype,info(i)); }
  46.  
  47. etype  operator[](itype y) const
  48.                            { stp i=lookup(Convert(y));
  49.                              if (i==nil) return init;
  50.                              else return ACCESS(etype,info(i)); }
  51.  
  52. bool defined(itype y) const { return (lookup(Convert(y)) != nil); }
  53.  
  54. void start_iteration()     { def_list.start_iteration(); }
  55. bool next_index(itype& y){ GenPtr p; bool b=def_list.next_element(p);
  56.                            y = ACCESS(itype,p); return b; }
  57.  
  58.  dph_array() { }
  59.  dph_array(int n,itype* I,etype* E): dp_hash(n,(GenPtr*)I,(GenPtr*)E) { }
  60.  dph_array(etype i) { init=i; }
  61.  
  62.  dph_array(const dph_array<itype,etype>& A): dp_hash((dp_hash&)A) { init = A.init; }
  63.  
  64. virtual ~dph_array() { def_list.clear(); }
  65. };
  66.  
  67.  
  68. #define forall_defined(i,A)  for ((A).start_iteration(); (A).next_index(i); )
  69.  
  70.  
  71. #endif
  72.